#include <linux/sched.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <wait.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char ** argv){
	pid_t pid = fork();
	if(pid < 0) {
		fprintf(stderr, "Fork Failed");
	}
	else if(pid == 0) {
    char *str = argv[1];
		int len = strlen(argv[1]);
    if( (len > 0 && str[0] == '-') || len == 0 ) {
      printf("%s is not a positive integer\n",str);
      return 0;
    }
    printf("sqeunce is [");
    int w = atoi(str);
    while(w != 1) {
      printf("%d ",w);
      w = (w & 1 ? 3*w+1 : (w>>1));
    }
    printf("%d]\n",w);
	}
	else {
		wait(NULL);
		printf("Child Complete\n");
	}
	return 0;
}

